{{ define "content" }}

<div class="nav-title">
    <a href="/">{{.SiteCf.Name}}</a> &raquo; - 编辑用户 {{.Uobj.Name}}
</div>

    <div class="main-box">
        <form method="post" action="" onsubmit="return form_flag_post();">
        <table cellpadding="5" cellspacing="8" border="0" width="100%" class="fs12">
            <tbody>
            <tr>
                <td width="120" align="right">设置权限</td>
                <td width="auto" align="left"><input type="text" class="sl w100" id="flag" value="{{.Uobj.Flag}}" /> 输入数字:0~99</td>
            </tr>
            <tr>
                <td width="120" align="right">权限说明</td>
                <td width="auto" align="left">
                    0: 禁用，不能发帖子、回复；<br/>
                    1: 等待审核，当开启注册用户审核才有效；<br/>
                    5: 一般用户，可发帖子、回复；<br/>
                    99： 管理员。
                </td>
            </tr>
            <tr>
                <td width="120" align="right"></td>
                <td width="auto" align="left"><input type="submit" value="保存设置" name="submit" class="textbtn" /></td>
            </tr>

            </tbody></table>
</form>

</div>

<a name="1"></a>
<div class="nav-title">基本资料 <span class="red">{{.Uobj.Name}}</span></div>
<div class="main-box">
    <form method="post" action="" onsubmit="return form_base_post();">
    <table cellpadding="5" cellspacing="8" border="0" width="100%" class="fs12">
        <tbody>
        <tr>
            <td width="120" align="right">隐藏用户</td>
            <td width="auto" align="left">
                <label><input type="checkbox" id="id-hidden" value="1" {{if .Uobj.Hidden}}checked="checked"{{end}} /> 隐藏</label>
            </td>
        </tr>
        <tr>
            <td width="120" align="right">登录名</td>
            <td width="auto" align="left"><input type="text" class="sl wb80" id="name" value="{{.Uobj.Name}}" /> <br/>一般不要修改</td>
        </tr>
        <tr>
            <td width="120" align="right">电子邮件</td>
            <td width="auto" align="left"><input type="text" class="sl wb80" id="email" value="{{.Uobj.Email}}" /> <br/>不公开，仅供取回密码</td>
        </tr>
        <tr>
            <td width="120" align="right">个人网站</td>
            <td width="auto" align="left"><input type="text" class="sl wb80" id="url" value="{{.Uobj.Url}}" /></td>
        </tr>
        <tr>
            <td width="120" align="right">个人简介</td>
            <td width="auto" align="left"><textarea class="ml wb80" id="about">{{.Uobj.About}}</textarea></td>
        </tr>
        <tr>
            <td width="120" align="right"></td>
            <td width="auto" align="left"><input type="submit" value="保存设置" name="submit" class="textbtn" /></td>
        </tr>
        </tbody></table>
    </form>

</div>

<a name="2"></a>
<div class="nav-title">为<span class="red">{{.Uobj.Name}}</span>设置头像</div>
<div class="main-box">
    <form action="" enctype="multipart/form-data" method="post">
        <input type="hidden" name="act" value="avatar" />
        <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
        <table cellpadding="5" cellspacing="8" border="0" width="100%" class="fs12">
            <tbody><tr>
                <td width="120" align="right">当前头像</td>
                <td width="auto" align="left">
                    <img id="av24" src="/static/avatar/{{.Uobj.Avatar}}.jpg?t={{.Now}}" class="avatar avatar24" border="0" align="default" auto=""> &nbsp;
                    <img id="av48" src="/static/avatar/{{.Uobj.Avatar}}.jpg?t={{.Now}}" class="avatar avatar48" border="0" align="default" auto=""> &nbsp;
                    <img id="av73" src="/static/avatar/{{.Uobj.Avatar}}.jpg?t={{.Now}}" class="avatar avatar73" border="0" align="default" auto="">
                </td>
            </tr>
            <tr>
                <td width="120" align="right">选择头像图片</td>
                <td width="auto" align="left"><input id="avatar" name="avatar" accept="image/*" type="file" /> (最大300K)</td>
            </tr>
            <tr>
                <td width="120" align="right"></td>
                <td width="auto" align="left"><input id="avatar_submit" type="submit" value="更新头像" name="submit" class="textbtn" /></td>
            </tr>

            </tbody></table>
    </form>
</div>

<a name="3"></a>
<div class="nav-title">为<span class="red">{{.Uobj.Name}}</span>重设密码</div>
<div class="main-box">
    <form method="post" action="" onsubmit="return form_pw_post();">
    <table cellpadding="5" cellspacing="8" border="0" width="100%" class="fs12">
        <tbody>
        <tr>
            <td width="120" align="right">新密码</td>
            <td width="auto" align="left"><input type="text" class="sl wb80" id="password" value="" /></td>
        </tr>
        <tr>
            <td width="120" align="right">再次输入新密码</td>
            <td width="auto" align="left"><input type="text" class="sl wb80" id="password2" value="" /></td>
        </tr>
        <tr>
            <td width="120" align="right"></td>
            <td width="auto" align="left"><input type="submit" value="重设密码" name="submit" class="textbtn" /></td>
        </tr>
        </tbody></table>
    </form>
</div>

<script>
    function form_flag_post(){
        var flag = $('#flag').val();

        $.ajax({
            type: "POST",
            url: "/admin/user/edit/{{.Uobj.Id}}",
            data: JSON.stringify({'act': 'flag', 'flag': parseInt(flag, 10)}),
            dataType: "json",
            contentType: "application/json",
            success: function(data){
                $.toast(data.retmsg);
            },
            fail: function(errMsg) {
                $.toast(errMsg);
            }
        });
        return false;
    }

    function form_base_post(){
        var hidden = $("#id-hidden:checked").val();
        var name = $('#name').val();
        var email = $('#email').val();
        var url = $('#url').val();
        var about = $('#about').val();

        $.ajax({
            type: "POST",
            url: "/admin/user/edit/{{.Uobj.Id}}",
            data: JSON.stringify({'act': 'info', 'hidden': hidden, 'name': name, 'email': email, 'url': url, 'about': about}),
            dataType: "json",
            contentType: "application/json",
            success: function(data){
                $.toast(data.retmsg);
            },
            fail: function(errMsg) {
                $.toast(errMsg);
            }
        });
        return false;
    }

    $("#avatar_submit").attr("disabled", true);
    function readFile() {
        if (this.files && this.files[0]) {
            var URL = window.URL || window.webkitURL;
            var file = this.files[0];
            var image = new Image();

            image.onload = function() {
                if (this.width) {
                    var FR= new FileReader();
                    FR.addEventListener("load", function(e) {
                        var buffer = e.target.result;
                        document.getElementById("av24").src = buffer;
                        document.getElementById("av48").src = buffer;
                        document.getElementById("av73").src = buffer;
                    });
                    FR.readAsDataURL(file);
                    $("#avatar_submit").attr("disabled", false);
                }
            };
            image.onerror = function() {
                $.toast("选择的文件不是图片格式");
                $("#avatar_submit").attr("disabled", true);
            };

            image.src = URL.createObjectURL(file);
        }
    }

    document.getElementById("avatar").addEventListener("change", readFile);

    function form_pw_post(){
        var password = $('#password').val();
        var password2 = $('#password2').val();
        if(password && password2){
            if(password != password2){
                $.toast('密码两次输入不同');
                $('#password').val('');
                $('#password2').val('');
                return false;
            }

            $.ajax({
                type: "POST",
                url: "/admin/user/edit/{{.Uobj.Id}}",
                data: JSON.stringify({'act': 'change_pw', 'password': md5(password)}),
                dataType: "json",
                contentType: "application/json",
                success: function(data){
                    $.toast(data.retmsg);
                    $('#password').val('');
                    $('#password2').val('');
                },
                fail: function(errMsg) {
                    $.toast(errMsg);
                }
            });
        }else{
            $.toast('密码必填');
        }
        return false;
    }
</script>

{{ end}}

